<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>短信记录</title>
<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		
		<link href="/static/weichat/css/style.css" rel="stylesheet" type="text/css" media="all" />
		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="/static/manage/common/bootstrap/js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>

</head>
<body>
	
<form class="form-inline" action="/bissmsrecord/" method="post">
	<p align="left">
  <div class="form-group">
    <label for="exampleInputName2">&nbsp;&nbsp;&nbsp;&nbsp;收件人:</label>
    <input type="text" class="form-control" id="mobile" name="mobile" placeholder="请输入手机号">
  </div>
  <div class="form-group">
    <label for="exampleInputName2">短信内容:</label>
    <input type="text" class="form-control" id="content" name="content" placeholder="请输入关键字">
  </div>
  <div class="form-group">
    			<label for="exampleInputName2">创建时间:</label>
    			<input type="date" class="form-control" id="start"  style="width:135px;height:32px;">
    			--至--
    			<input type="date" class="form-control" id="end"  style="width:135px;height:32px;" >
  </div>
  </p>
  <p align="left">
  	<div class="form-group">
   				<label for="exampleInputName2">短信类型:</label>
  				<select class="form-control" id="sms_type" name="sms_type">
  					<option value="">---------------------------------</option>
  					<option value="1">普通短信</option>
  					<option value="2">验证短信</option>
  					<option value="3">支付验证短信</option>
  				</select>
  	</div>
  	<div class="form-group">
   				<label for="exampleInputName2">发送状态:</label>
  				<select class="form-control" id="status" name="status">
  					<option value="">--------------------------------</option>
  					<option value="0">失败</option>
  					<option value="1">成功</option>
  					
  	</select>
  	<div class="form-group">
    			<label for="exampleInputName2">发送时间:</label>
    			<input type="date" class="form-control" id="start1"  style="width:135px;height:32px;">
    			--至--
    			<input type="date" class="form-control" id="end1"  style="width:135px;height:32px;" >
  </div>
  	
  	</div>
  	<button type="button" class="btn btn-primary" id="but2">搜索</button>
   	<button type="reset" class="btn btn-primary" >重置</button>
  </p>
</form>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal2">发送信息</button>
<button type="button" class="btn btn-primary" id="del" onclick="del()">删除信息</button>
	<!-- 
	<button class="btn btn-success" data-toggle="modal"
		data-target="#myModal2" id="ssele">发送信息</button>
	<button class="btn btn-warning" onclick="dele()">删除信息</button> -->
	<form id="fm2">
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 700px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">发送信息</h4>
					</div>
					<table>
						<tr>
							<td>发送用户：</td>
							<td><input type="text" style="width: 500px; height: 100px;"
								id="user" name="mobile" /></td>
							<td>
								请输入发送手机号,多个手机号以","符号隔开
							</td>
						</tr>
						<br />
						<tr>
							<td>发送内容 :</td>
							<td><input type="text"
								style="width: 500px; height: 150px;" id="neirong" name="content" /></td>
						<td>字数小于等于 70 字，按 1 条扣费； 大于将按每 67 字扣 1 条计算</td>
						</tr>
					</table>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="updatebtn2">发送</button>
					</div>
				</div>
			</div>
		</div>
	</form>
	
	<div>
			<table id="table">

			</table>
		</div>
</body>

<script type="text/javascript">
	function changeDateFormat(cellval) {
        var dateVal = cellval + "";
        if (cellval != null) {
            var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            
            var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
            var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
            
            return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
        }
    }
	</script>
		
		
		<script type="text/javascript">
		
			$(function() {
				
			

				//1.初始化Table

				var oTable = new TableInit();

				oTable.Init();

				var message = document.getElementById("message").value;

				if(message != null && message != "") {

					alert(message);

				}
			});
				
				
				var TableInit=function(){
					var oTableInit=new Object();
					//初始化table
					oTableInit.Init=function(){
						
					
					
				$("#table").bootstrapTable({
					method:'get',
					contentType:"application/x-www-form-urlencoded",
					url:"/bissmsrecord/",	//请求后台的url（*）
						striped: true, //是否显示行间隔色

						locale: 'zh-CN', //中文支持

						pagination: true, //是否开启分页（*）

						pageNumber: 1, //初始化加载第一页，默认第一页

						pageSize: 2, //每页的记录行数（*）

						pageList: [2, 3, 4], //可供选择的每页的行数（*）

						sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）

						/* showRefresh: true, //刷新按钮 */

						queryParams: oTableInit.queryParams, //传递参数（*）

						strictSearch: true,

						/* showColumns: true, //是否显示所有的列 */

						/* showRefresh: true, //是否显示刷新按钮 */

						minimumCountColumns: 2, //最少允许的列数

						/* clickToSelect: true, //是否启用点击选中行 */

						uniqueId: "project_id", //每一行的唯一标识，一般为主键列

						columns: [{
							title: '<input type="checkbox" id="all" onclick="checkAll()"/>',
							align: 'center',
							width:'40',
							formatter: function (value, row, index) {
							    return '<input name="che" type="checkbox" value="'+row.record_id+'"/>'
							}
						},{
							field: 'mobile',
							title: '手机号码',
							align: 'center',
						},{
							field: 'content',
							title: '内容',
							align: 'center',
						},{
							field: 'sms_type',
							title: '短信类型',
							align: 'center',
							formatter:function(v,r,i){
								switch (Number(v)){
									case 1:
										return "普通短信";
										break;
									case 2:
										return "验证短信";
										break;
									case 3:
										return "支付验证短信";
										break;
								}
							}
						},{
							field: 'status',
							title: '信息状态',
							align: 'center',
							formatter:function(v,r,i){
								switch (Number(v)){
									case 0:
										return "失败";
										break;
									case 1:
										return "成功";
										break;
									
								}
							}
						},{
							field: 'create_time',
							title: '创建时间',
							align: 'center',
							formatter: function (value, row, index) {
                				return changeDateFormat(value)
							}
						},{
							field: 'send_time',
							title: '发送时间',
							align: 'center'	,
							formatter: function (value, row, index) {
                				return changeDateFormat(value)
							}
						},{
							field: 'failure_cause',
							title: '发送失败原因',
							align: 'center'	
							
						}]
					});
					};
			
					//得到查询的参数

					oTableInit.queryParams = function(params) {

						var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的

							limit: params.limit, //页面大小

							offset: params.offset, //偏移量
							pageSize:params.limit,
							mobile:$("#mobile").val(),
							content:$("#content").val(),
							start:$("#start").val(),
							end:$("#end").val(),
							sms_type:$("#sms_type").val(),
							status:$("#status").val(),
							start1:$("#start1").val(),
							end1:$("#end1").val(),
						};
						return temp;
					};
					return oTableInit;
				};
				
				
				
				
				
				
				
				
				$('#but2').click(function(){
					
					$("#table").bootstrapTable('refresh');
				})
				
			
$("#updatebtn2").click(function() {//发送按钮
			if ($("#user").val() != "") {
				$.ajax({
					type : "get",
					url : "/bissmsrecord/add",
					data : $("#fm2").serialize(),
					success : function(data) {
						if (data != 0) {
							location.reload();
						}
					}
				})
			} else {
				alert("请填写手机号！")
			}
		})
			function checkAll () {
				var allche = document.getElementById("all");
				var ches = document.getElementsByName("che");
				for (i = 0; i < ches.length; i++) {
					ches[i].checked = allche.checked;
				}
			}
			
			function findIds(ename) {
				arr = document.getElementsByName(ename);
				ids = [];
				for (k in arr) {
					if (arr[k].checked)
						ids.push(arr[k].value);
				}
				return ids;
			}
				
				//删除
			function del () {
				alert(111111)
				alert(findIds("che").length)
				if (findIds("che").length!=0) {
					
					$.ajax({
						type:"get",
						url:"/bissmsrecord//delrecord?record_id="+findIds("che"),
						async:true,
						success:function (data) {
							if (data!=0) {
								alert("删除成功！！！")
								$("#table").bootstrapTable('refresh');
							} else{
								alert("删除失败！！！")
							}
						}
					});
					
				} else {
					alert("亲，请先选择你要删除的数据！！！")
				}				
			}
			
		</script>

</html>